package cc.vicp.djx314.starfood.web.test;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import cc.vicp.djx314.starfood.domain.dish.Dish;

/**
 * rest及json，xml视图测试类
 * @author Administrator
 *
 */
@Controller
public class JsonXmlRestTestController {
	@Resource(name = "adminRecommendDishes")
	private List<Dish> dishes;

	@Resource(name = "dish1")
	private Dish dish1;

	/**
	 * 返回json视图
	 * @return
	 */
	@RequestMapping("/show/json")
	public ModelAndView json() {
		ModelAndView model = new ModelAndView("jsontournamenttemplate");
		model.addObject("mydish", dish1);
		return model;
	}

	/**
	 * 返回xml视图
	 * @return
	 */
	@RequestMapping("/show/xml")
	public ModelAndView xml() {
		ModelAndView model = new ModelAndView("xStreamMarshallingView");
		model.addObject(BindingResult.MODEL_KEY_PREFIX, dish1);
		return model;
	}

	/**
	 * rest风格delete方法通过get来请求
	 * @param id
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/show/{id}", method = RequestMethod.DELETE)
	public ModelAndView rest(@PathVariable("id") Integer id, HttpServletRequest request,
			HttpServletResponse response) {
		ModelAndView model = new ModelAndView("xStreamMarshallingView");
		model.addObject("id", id);
		return model;
	}
}
